package main

import "fmt"

func main() {
	// a1()
	// a2()
	// a3()

	// a1 := [...]int{10, 30, 50}
	// fmt.Printf("%v, %p\n", a1, &a1)
	// a2 := a1
	// fmt.Printf("%v, %p\n", a2, &a2)
	// fmt.Println("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~")
	// a3 := showAddr(a1)
	// fmt.Printf("%v, %p\n", a3, &a3)
	a4()
}

func a4() {
	var s1 []int
	var s2 = []int{}
	var s3 = []int{1, 2, 3}
	var s4 = make([]int, 0)
	var s5 = make([]int, 3, 5)
	fmt.Println(s1, s2, s3, s4, s5)

	a := []int{1, 3, 5, 7}
	fmt.Printf("%v, %p, %p\n", a, &a, &a[0])

	s6 := make([]int, 3, 5)
	fmt.Printf("s6 %p, %p, 1en=%-2d,cap=%-2d, %v\n", &s6, &s6[0], len(s6), cap(s6), s6)
	s7 := append(s6, 1, 2)
	fmt.Printf("s6 %p, %p, 1en=%-2d,cap=%-2d, %v\n", &s6, &s6[0], len(s6), cap(s6), s6)
	fmt.Printf("s7 %p, %p, 1en=%-2d,cap=%-2d, %v\n", &s7, &s7[0], len(s7), cap(s7), s7)
	s8 := append(s6, -1)
	fmt.Printf("s6 %p, %p, 1en=%-2d,cap=%-2d, %v\n", &s6, &s6[0], len(s6), cap(s6), s6)
	fmt.Printf("s7 %p, %p, 1en=%-2d,cap=%-2d, %v\n", &s7, &s7[0], len(s7), cap(s7), s7)
	fmt.Printf("s8 %p, %p, 1en=%-2d,cap=%-2d, %v\n", &s8, &s8[0], len(s8), cap(s8), s8)
	s9 := append(s6, 3, 4, 5)
	fmt.Printf("s6 %p, %p, 1en=%-2d,cap=%-2d, %v\n", &s6, &s6[0], len(s6), cap(s6), s6)
	fmt.Printf("s7 %p, %p, 1en=%-2d,cap=%-2d, %v\n", &s7, &s7[0], len(s7), cap(s7), s7)
	fmt.Printf("s8 %p, %p, 1en=%-2d,cap=%-2d, %v\n", &s8, &s8[0], len(s8), cap(s8), s8)
	fmt.Printf("s9 %p, %p, 1en=%-2d,cap=%-2d, %v\n", &s9, &s9[0], len(s9), cap(s9), s9)

}

func showAddr(arr [3]int) [3]int {
	fmt.Printf("%v, %p\n", arr, &arr)
	return arr
}

func a3() {
	var a0 [3]int
	var a1 = [3]int{}

	var a2 [3]int = [3]int{1, 3, 5}
	var a3 = [3]int{1, 3, 5}

	const count = 3
	a4 := [count]int{1, 3, 5}
	fmt.Println(a0, a1, a2, a3, a4)

	a5 := [...]int{1, 3, 5}
	a6 := [5]int{100, 200}
	a7 := [5]int{1: 300, 3: 400}
	fmt.Println(a5, a6, a7)

	a8 := [2][3]int{{100}}
	fmt.Println(a8)
	a9 := [...][3]int{{10}, {11, 12}, {13, 14, 15}, {16}}
	fmt.Println(a9)

	a5 = [...]int{10, 30, 50}
	a5[0] += 100
	fmt.Println(a5)

	for i := 0; i < len(a5); i++ {
		fmt.Println(i, a5[i])
	}

	for i, v := range a5 {
		fmt.Println(i, v, a5[i])
	}

	var b [3]int
	for i := 0; i < len(b); i++ {
		fmt.Println(i, b[i], &b[i])
	}
	fmt.Printf("%p %p, %v\n", &b, &b[0], b)

	var c = [3]string{"abc", "def", "xyz"}
	for i := 0; i < len(c); i++ {
		fmt.Println(i, c[i], &c[i])
	}
	fmt.Printf("%p %p %v\n", &c, &c[1], c)
	c[0] = "oooooo"
	fmt.Printf("%p %p %v\n", &c, &c[0], c)

}

func a2() {
	var n int
	var err error
	var name string
	var age int
	fmt.Print("Plz input your name and age: ")
	n, err = fmt.Scanf("%s %d", &name, &age)
	// n, err = fmt.Scanf("%s,%d", &name, &age) // 最好默认空格做分隔符，用逗号，如果第一个参数是字符串，会把逗号单做字符串的一部分就没法获取后面部分
	if err != nil {
		panic(err)
	}
	fmt.Println(n, name, age)

	var weight, height int
	fmt.Print("weight and height: ")
	_, err = fmt.Scanf("%d %d", &weight, &height)
	if err != nil {
		panic(err)
	}
	fmt.Printf("%T %[1]d, %T %[2]d\n", weight, height)
}

func a1() {
	var n int
	var err error

	var word1, word2 string
	fmt.Print("Plz input two words: ")
	n, err = fmt.Scan(&word1, &word2)
	if err != nil {
		panic(err)
	}
	fmt.Println(n)
	fmt.Printf("%T %s,%T %s\n", word1, word1, word2, word2)
}
